class TasksController < ApplicationController

  def index
    @task = Task.new
  end  

  def create
    @task = Task.new(params[:task])
    @task.save ? redirect_to(tasks_url) : render(:index )    
  end

  def edit
    @task = Task.find(params[:id])
    params[:type] = "waiting" if not params[:type].present?
  end

  def update
    @task = Task.find(params[:id])
    render :edit if not @task.update_attributes(params[:task])
  end

  def destroy
    params[:type] = "waiting" if not params[:type].present?
    @task = Task.find(params[:id])
    @task.destroy
  end
  
  def completed
    @task = Task.find(params[:id])
    @task.completed!
  end

  def waiting
    @task = Task.find(params[:id])
    @task.waiting!
  end
end
